﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

// 技能对象
public class SkillObj
{
    public BuffBase Logic;
    public BuffData Data;
}

// 主角技能
public class PlayerSkillMgr
{
    HumanCtrl _owner;

    List<BuffBase> _allSkill = new List<BuffBase>();

    // skillid, skillObj
    Dictionary<int, SkillObj> _nowSkills = new Dictionary<int, SkillObj>();

    public void Init(HumanCtrl owner)
    {
        _owner = owner;

        _allSkill.Add(new BuffProtect());
        _allSkill.Add(new BuffFly());
        _allSkill.Add(new BuffBig());
        _allSkill.Add(new BuffMagnet());
    }

    public void AddSkill(int id)
    {
        SkillObj obj;
        if (!_nowSkills.TryGetValue(id, out obj))
        {
            obj = new SkillObj();
            _nowSkills.Add(id, obj);
            obj.Logic = _allSkill[id - 1];
            obj.Logic.Init(id, _owner, onSkillEnd);
        }
        obj.Logic.AddDuring(3); // 假设持续3秒
    }

    public void OnBolckEnter(Transform other)
    {
        foreach (var vk in _nowSkills)
        {
            vk.Value.Logic.OnBlockEnter(other);
        }
    }

    // 撞到敌人，true：杀死敌人
    public bool OnEnemyEnter(Enemy other)
    {
        bool bAttackEnemy = false;
        foreach (var vk in _nowSkills)
        {
            bAttackEnemy = bAttackEnemy || vk.Value.Logic.OnEnemyEnter(other);
        }

        return bAttackEnemy;
    }

    private void onSkillEnd(int id)
    {
        _nowSkills.Remove(id);
        //throw new NotImplementedException();
    }
}

